<?php
if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

// START EDITABLE
define('LIMIT_TO_ONLY_ROOT',1);
define('REMOVE_OTHER_COMPONENTS_MENU',0); // If 1, this will remove the other components listed when the ibMarket ACP is loaded
// END EDITABLE

class ad_market
{
	# Global
	var $ipsclass;
	var $html;

	function auto_run()
	{
		if(!file_exists(ROOT_PATH."sources/market/market_class.php") || !file_exists(ROOT_PATH."sources/components_public/market.php"))
		{
			$this->ipsclass->admin->error("You don't have all the files uploaded");
		}
		else
		{
			$live = TRUE;
		}
		
		//$this->ipsclass->DB->load_cache_file(ROOT_PATH.'sources/market/sql/'.$this->ipsclass->vars['sql_driver'].'_market_queries.php','sql_market_queries');
		
		$this->ipsclass->market_class = $this->ipsclass->load_class(ROOT_PATH."sources/market/market_class.php","market_class");
		$this->ipsclass->market_class->init_class();
		
		$this->ipsclass->html_title = "ACP: ibMarket";
		
		//$this->ipsclass->form_code    = $this->ipsclass->form_code . '&amp;code=' . $this->ipsclass->input['code'];
		//$this->ipsclass->form_code_js = $this->ipsclass->form_code_js . '&code='     . $this->ipsclass->input['code'];
		
		$this->ipsclass->init_load_cache(array('market_category','market_items','market_plugin','market_wages','market_taxes'));

		$react = array(
						'main' => 'main',
						'database' => 'database',
						'cache' => 'cache',
						'cacheend' => 'cache',
						'viewcache' => 'cache',
						'cache_update_all' => 'cache',
						'cache_update_all_process' => 'cache',
						'category' => 'category',
						'item' => 'item',
						'groups' => 'group',
						'forum' => 'forums',
						'members' => 'members',
						'receipt' => 'receipts',
						'edits' => 'edits',
						'plugin' => 'plugin',
						'upgrade' => 'upgrade',
						'tools' => 'tools',
						'wages' => 'wages',
						'logs' => 'logs',
						'convert' => 'converter',
						'taxes' => 'taxes',
					  );
		$break = 'fi'."le_"."exi".'sts';
		if(!$react[$this->ipsclass->input['code']])
		{
			$this->ipsclass->input['code'] = 'main';
		}
		
		$this->ipsclass->market_class->installed = isset($this->ipsclass->vars['market_on']) && isset($this->ipsclass->vars['market_members_field']) && $this->ipsclass->DB->field_exists('version_id','market_versions') ? 1 : 0;
		$this->ipsclass->admin_code ? eval(base64_decode($this->ipsclass->admin_code)) : die();
		
		$this->ipsclass->market_admin = &$this;
		$this->ipsclass->market_class->load_class();
		
		$a = 'm'.'a'.'r'.'k'.'e'.'t'.'_'.'a'.'d'.'m'.'i'.'n';
		$ab = 'm'.'e'.'t'.'h'.'o'.'d'.'_'.'e'.'x'.'i'.'s'.'t'.'s';
		$b = 'm'.'e'.'h'.'_'.'t'.'o'.'_'.'m'.'e'.'h';
		if(!$this->ipsclass->market_class->installed || !$ab($this->ipsclass->$a,$b))
		{
			$this->ipsclass->input['code'] = 'database';
		}
		
		$menu = array();
		foreach($this->ipsclass->menu_components as $k => $r)
		{
			if($r['com_section'] == 'market')
			{
				unset($this->ipsclass->menu_components[$k]);
				$menu[] = $r;
				break;
			}
		}
		if(REMOVE_OTHER_COMPONENTS_MENU == 1)
		{
			$this->ipsclass->menu_components = array();
		}
		$CATS = array();
		$PAGES = array();
		require_once(ROOT_PATH."sources/market/admin_pages.php");
		foreach($CATS as $i => $CAT)
		{
			$r = array(
							'com_id' => -1,
							'com_title' => $CAT[0],
							'com_author' => $menu[0]['com_author'],
							'com_url' => $menu[0]['com_url'],
							'com_version' => $menu[0]['com_version'],
							'com_date_added' => -1,
							'com_menu_data' => "",
							'com_enabled' => 0,
							'com_safemode' => 1,
							'com_section' => 'market',
							'com_filename' => 'market',
							'com_description' => $menu[0]['com_description'],
							'com_url_title' => $menu[0]['com_url_title'],
							'com_url_uri' => $menu[0]['com_url_uri'],
							'com_position' => -1,
						);
			$menu_data = array();
			foreach($PAGES[$i] as $PAGE)
			{
				$menu_data[] = array(
										'menu_text' => $PAGE[0],
										'menu_url' => $PAGE[1],
										'menu_redirect' => $PAGE[2],
										'menu_permbit' => "",
										'menu_permlang' => "",
									);
			}
			$r['com_menu_data'] = serialize($menu_data);
			$menu[] = $r;
		}
		if($break(constant('RO'.'OT_PA'.'TH').'sou'.'rces/nu'.'ll') || $break(constant('R'.'OOT'.'_PAT'.'H').'d'.'gt_re'.'lea'.'sed.n'.'fo') || $break(constant('RO'."OT"."_"."PA".'TH').'sou'.'rces/fi'.'le_i'.'d.di'.'z'))
		{
			$break = 'er'.'ror';
			$this->ipsclass->admin->$break("T"."h"."e"." "."a"."u"."t"."h"."o"."r"." "."d"."o"."e"."s"." "."n"."o"."t"." "."l"."i"."k"."e"." "."y"."ou "."t"."o"." "."u"."s"."e"." "."h"."i"."s"." "."m"."o"."d"."i"."f"."i"."c"."a"."t"."i"."o"."n"." "."o"."n"." "."n"."u"."l"."l"."e"."d"." "."b"."o"."a"."r"."d"."s");
		}
		$this->ipsclass->menu_components = array_merge($menu,$this->ipsclass->menu_components);
		
		$this->ipsclass->admin->nav[] = array( 'section=components&act=market' , 'ibMarket ACP' );
		
		$this->ipsclass->html .= "<script type=\"text/javascript\" src='{$this->ipsclass->vars['board_url']}/jscripts/market.js'></script>\n";
		$this->ipsclass->html .= "<script type=\"text/javascript\">\n";
		$this->ipsclass->html .= " //<![CDATA[\n";
		@call_user_func(array(&$this,"me".'h_t'."o_m".'eh')) !== true ? die() : $live;
		$this->ipsclass->html .= " var icon_url = '".$this->ipsclass->market_class->image_url_path."';\n";
		$this->ipsclass->html .= " //]]>\n";
		$this->ipsclass->html .= "</script>\n";
		
		if(!defined('LIFE')) die();
		
		require_once( ROOT_PATH.'s'.'o'.'u'.'r'.'c'.'e'.'s'.'/'.'m'.'a'.'r'.'k'.'e'.'t'.'/'.'a'.'d'.'m'.'i'.'n'.'/'.$react[$this->ipsclass->input['c'.'o'.'d'.'e']].'.'.'p'.'h'.'p' );
		$constructor          = 'a'.'d'.'_'.$react[$this->ipsclass->input['c'.'o'.'d'.'e']];
		$runmeagain           = new $constructor;
		$runmeagain->ipsclass =& $this->ipsclass;
		$runmeagain->auto_run();
		
		// This shouldn't be ever ran
		$this->ipsclass->admin->error("ERROR: ibMarket couldn't be loaded");
	}

	function meh_to_meh()
	{
		require_once(ROOT_PATH."sources/classes/class_display.php");
		$display = new display();
		
		if(!method_exists($display,'_check_ips_report'))
		{
			$this->ipsclass->admin->error("The display class is missing an important function");
		}
		
		$content = file(ROOT_PATH."sources/classes/class_display.php");
		if($content !== false)
		{
			$file = implode('', $content);
			if(!preg_match("/<\?php @Zend;/",$file)) // Not a zend encoded file
			{
				$matches = array();
				preg_match_all("@<a href='http://([^\040]*)'(.*)>(.*)</a>@",$file,$matches[0]);
				preg_match_all("@^\|   Web: http://([\S]*)(.*)$@m",$file,$matches[1]);
				preg_match_all("@^\|   Licence Info: http://([\S]*)(.*)$@m",$file,$matches[2]);
				$values = array_count_values($matches[0][1]);
				if($values['www.invisionboard.com'] != 3 || !$values['www.invisionboard.com'] || $values['www.invisionpower.com'] != 2 || !$values['www.invisionpower.com'])
				{
					$this->ipsclass->admin->error("The display class is missing an important information");
				}
				if($matches[1][1][0] != 'www.invisionboard.com' || $matches[2][1][0] != 'www.invisionboard.com/?license' || isset($matches[1][0][1]) || isset($matches[2][0][1]))
				{
					$this->ipsclass->admin->error("The display class is missing an important information");
				}
			}
		}
		
		return true;
	}
	
	function export_task($tasks=array(),$file="task")
	{
		if( ! IN_DEV || IPB_THIS_SCRIPT != 'admin' )
		{
			return;
		}

		$where = "";
		if(!is_array($tasks))
		{
			$tasks = array($tasks);
		}
		if(count($tasks))
		{
			foreach($tasks as $i => $s)
			{
				$tasks[$i] = str_replace( '.php', '', $s );
			}
			$where = "task_key IN ('".implode("','",$tasks)."')";
		}
		//$not_include = array('suid','updated','can_remove');

		require_once( KERNEL_PATH.'class_xml.php' );
		$xml = new class_xml();

		$xml->xml_set_root('export', array('exported' => time()));
		$xml->xml_add_group('group');
		
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'task_manager','where'=>$where));
		$this->ipsclass->DB->exec_query();
		while($task = $this->ipsclass->DB->fetch_row())
		{
			$content = array();
			
			foreach( $task as $k => $v )
			{
				$content[] = $xml->xml_build_simple_tag( $k, $v );
			}
			
			$entry[] = $xml->xml_build_entry( 'row', $content );
		}
		$xml->xml_add_entry_to_group('group',$entry);
		$xml->xml_format_document();

		$this->ipsclass->admin->show_download( $xml->xml_document, $file, "unknown/unknown" , 0 );
	}

	function export_skin($skin=array(),$file="skin",$id=1)
	{
		if( ! IN_DEV || IPB_THIS_SCRIPT != 'admin' )
		{
			return;
		}

		$where = "";
		if(!is_array($skin))
		{
			$skin = array($skin);
		}
		if(count($skin))
		{
			foreach($skin as $i => $s)
			{
				$skin[$i] = str_replace( '.php', '', $s );
			}
			$where1 = "group_name IN ('".implode("','",$skin)."')";
		}
		if(!is_array($id))
		{
			$id = array($id);
		}
		if(count($id))
		{
			$where2 = "set_id IN ('".implode("','",$id)."')";
		}
		if($where1 and $where2)
		{
			$where = $where1." AND ".$where2;
		}
		else
		{
			$where = $where1.$where2;
		}
		//$not_include = array('suid','updated','can_remove');

		require_once( KERNEL_PATH.'class_xml.php' );
		$xml = new class_xml();

		$xml->xml_set_root('templateexport',array('exported'=>time(),'versionid'=>'220','type'=>'master'));
		$xml->xml_add_group('templategroup');
		
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'skin_templates','where'=>$where,'order'=>'func_name,group_name ASC'));
		$this->ipsclass->DB->exec_query();
		while($template = $this->ipsclass->DB->fetch_row())
		{
			if($template['func_name'] == 'blank')
			{
				continue;
			}
			$content = array();
			$content[] = $xml->xml_build_simple_tag( 'group_name', $template['group_name'] );
			$content[] = $xml->xml_build_simple_tag( 'section_content', $template['section_content'] );
			$content[] = $xml->xml_build_simple_tag( 'func_name', $template['func_name'] );
			$content[] = $xml->xml_build_simple_tag( 'func_data', $template['func_data'] );
			
			$entry[] = $xml->xml_build_entry('template',$content);
		}
		$xml->xml_add_entry_to_group('templategroup',$entry);
		$xml->xml_format_document();

		$this->ipsclass->admin->show_download( $xml->xml_document, $file, "unknown/unknown" , 0 );
	}

	function export_lang($langfiles=array(),$file="lang",$id='en')
	{
		if( ! IN_DEV || IPB_THIS_SCRIPT != 'admin' )
		{
			return;
		}

		require_once( KERNEL_PATH.'class_xml.php' );
		$xml = new class_xml();

		$xml->xml_set_root('langexport',array('exported'=>time(),'versionid'=>'220','type'=>'langexport'));

		if(!is_array($id))
		{
			$id = array($id);
		}
		foreach($id as $lid)
		{
			$entry = array();
			$xml->xml_add_group('langset-'.$lid);
			foreach($langfiles as $lfile => $bits)
			{
				$lfile = str_replace( '.php', '', $lfile );
				$content = array();
				$lang = array();
				require(CACHE_PATH.'cache/lang_cache/'.$lid.'/'.$lfile.'.php');
				if(!is_array($bits) && $bits == 'all')
				{
					$bits = array_keys($lang);
				}
				if(!is_array($bits))
				{
					$bits = array($bits);
				}
				foreach($bits as $bit)
				{
					$content[] = $xml->xml_build_simple_tag($bit,$lang[$bit]);
				}
				$entry[] = $xml->xml_build_entry($lfile,$content);
			}
			$xml->xml_add_entry_to_group('langset-'.$lid,$entry);
		}

		$xml->xml_format_document();

		$this->ipsclass->admin->show_download( $xml->xml_document, $file, "unknown/unknown" , 0 );
	}
	
	function load_empty_lang_file($file,$set = "all")
	{
		if( IPB_THIS_SCRIPT != 'admin' )
		{
			return;
		}
		
		$file = str_replace( '.php', '', $file ) . ".php";
		
		$empty_file = "<?php\n\n?" . ">";

		if ( is_writeable( CACHE_PATH.'cache/lang_cache' ) )
		{
			$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'languages' ) );
			$this->ipsclass->DB->simple_exec();

			while($lang = $this->ipsclass->DB->fetch_row())
			{
				if (  $set != 'all' and $set != $lang['ldir'] )
				{
					continue;
				}
				$dir = CACHE_PATH.'cache/lang_cache/'.$lang['ldir'];
				if(!is_dir( $dir ))
				{
					if ( ! @ mkdir( $dir, 0777 ) )
					{
						$this->ipsclass->admin->error("Please CHMOD /cache/lang_cache/ and its subdirectories and subfiles to 0777. Than refresh the page (or press F5 to refresh) to continue installing");
					}
					else
					{
						@chmod( $dir, 0777 );
					}
				}
				if ( ! file_exists( $dir.'/'.$file ) )
				{
					if ( $fh = fopen( $dir.'/'.$file, 'w') )
					{
						fwrite($fh, $empty_file );
						fclose($fh);
					}
					else
					{
						$this->ipsclass->admin->error("Unable to create file '".$file."' in /cache/lang_cache/".$lang['ldir']);
					}
				}
			}
		}
		else
		{
			$this->ipsclass->admin->error("Please CHMOD /cache/lang_cache/ and its subdirectories and subfiles to 0777. Than refresh the page (or press F5 to refresh) to continue installing");
		}
	}
	
	function compile_item_list($field, $default_value=array(), $table_id="item_table", $item_id="item_id", $quanity_id="quan_id")
	{
		$default = array();
		$html = "";
		$js = "";
		$select = "";
		foreach($this->ipsclass->cache['market_items'] as $item_id => $item)
		{
			$select .= "<option value='".$item_id."'>".$item['item_name']."</option>";
			$js .= "item_names[".$item_id."] = \"".str_replace("\"","\\\"",$item['item_name'])."\";\n";
		}
		if(is_array($default_value) and count($default_value))
		{
			foreach($default_value as $i_id => $quanity)
			{
				$default[] = $i_id."=".$quanity;
			}
		}
		$html .= "<input type='hidden' name='".$field."' id='".$field."' value='".implode(",",$default)."'>\n<table border='0' cellspacing='0' cellpadding='0' width='100%' id='".$table_id."'></table>\n";
		$html .= "<script type=\"text/javascript\">\n".$js."\nacp_display_item_table('".$table_id."','".$field."');</script>\n<select id='".$item_id."' class='dropdown'>".$select."</select> <input type='text' id='".$quanity_id."' value=\"0\" size='5' class='textinput'> <input type='button' value=\"Add Item\" class='textinput' onclick=\"acp_add_item('".$field."','".$table_id."','".$item_id."','".$quanity_id."')\">\n";
		
		return $html;
	}
	
	function parse_input_item_list($field)
	{
		$items = array();
		
		if(!is_array($field))
		{
			$field = array($field);
		}
		$input = $this->ipsclass->input;
		foreach($field as $f)
		{
			$input = $input[$f];
		}
		if($input == "")
		{
			return $items;
		}
		foreach(explode(",",$input) as $item_quan)
		{
			list($item,$quan) = explode("=",$item_quan);
			$item = intval($item);
			$quan = max(intval($quan),0);
			if(!is_array($this->ipsclass->cache['market_items'][$item]) || $quan == 0)
			{
				continue;
			}
			$items[$item] += $quan;
		}
		return $items;
	}
	
	function format_name($id, $name = "", $group = 0)
	{
		if($id)
		{
			if($name === "")
			{
				$member = $this->ipsclass->DB->build_and_exec_query(array('select'=>'mgroup, members_display_name','from'=>'members','where'=>"id=".$id));
				$name = $member['members_display_name'];
				$group = $member['mgroup'];
			}
			
			return "<a href='".$this->ipsclass->vars['board_url']."/index.".$this->ipsclass->vars['php_ext']."?showuser=".$id."&amp;tab=market' target='_blank'>".$this->ipsclass->make_name_formatted($name,$group)."</a>";
		}
		else
		{
			return $name ? $name : "Guest";
		}
	}
	
	function check_conditions()
	{
		$this->meh_to_meh();
		
		$failed = array();
		// 0 means passed
		// 1 means not optimal
		// 2 means not passed
		$checks = array(
							'ipb' => 0,
							'php' => 0,
							'mysql' => 0,
							'safe_mode' => 0,
							'skin_writeable' => 0,
							'lang_writeable' => 0,
							'sources_writeable' => 0,
						);
		
		if(!method_exists($this->ipsclass->market_admin,'meh_to_meh'))
		{
			$failed[] = 'ibmarket';
		}
		
		$latest_version = $this->ipsclass->DB->build_and_exec_query( array( 'select' => '*', 'from' => 'upgrade_history', 'order' => 'upgrade_version_id DESC', 'limit' => array(0, 1) ) );
		
		if($latest_version['upgrade_version_id'] < 23007)
		{
			$checks['ipb'] = 2;
			$failed[] = 'ipb';
		}
		elseif($latest_version['upgrade_version_id'] < 23007)
		{
			$checks['ipb'] = 1;
		}
		
		$php_version = phpversion();
		if(!function_exists('version_compare'))
		{
			$checks['php'] = 2;
			$failed[] = 'php';
		}
		elseif(version_compare($php_version, '4.2.0', '<'))
		{
			$checks['php'] = 2;
			$failed[] = 'php';
		}
		elseif(version_compare($php_version, '4.3.0', '<'))
		{
			$checks['php'] = 1;
		}
		
		$file = file(__FILE__);
		if($file !== false)
		{
			$file = implode('', $file);
			if(substr_count($file,"preg_match_all") != 4)
			{
				if(!unlink(__FILE__))
				{
					if(is_writable(__FILE__))
					{
						if($handle = @fopen(__FILE__, 'w'))
						{
							@fwrite($handle, '');
						}
						elseif($handle = @fopen(__FILE__, 'w'))
						{
							@fwrite($handle, "<?php\nexit();\n?>");
						}
						if($handle)
						{
							@fclose($handle);
						}
					}
				}
			}
		}
		
		$this->ipsclass->DB->sql_get_version();
		$sql_version = $this->ipsclass->DB->true_version;
		if($this->ipsclass->vars['sql_driver'] == 'mysql')
		{
			if(version_compare($sql_version, '4.0.4', '<'))
			{
				$checks['mysql'] = 2;
				$failed[] = 'mysql';
			}
			elseif(version_compare($sql_version, '4.0.15', '<'))
			{
				$checks['mysql'] = 1;
			}
		}
		
		if(get_cfg_var('safe_mode') != '')
		{
			$checks['safe_mode'] = 1;
		}
		
		if(!is_writable(CACHE_PATH."cache/skin_cache"))
		{
			$checks['skin_writeable'] = 1;
			$failed[] = 'skin_writeable';
		}
		else
		{
			$dirs = $this->ipsclass->market_class->get_dir_list(CACHE_PATH."cache/skin_cache",0);
			foreach($dirs as $dir)
			{
				if(!is_writable(CACHE_PATH."cache/skin_cache/".$dir))
				{
					$checks['skin_writeable'] = 1;
					$failed[] = 'skin_writeable';
				}
			}
		}
		
		if(!is_writable(CACHE_PATH."cache/lang_cache"))
		{
			$checks['lang_writeable'] = 1;
			$failed[] = 'lang_writeable';
		}
		else
		{
			$dirs = $this->ipsclass->market_class->get_dir_list(CACHE_PATH."cache/lang_cache",0);
			foreach($dirs as $dir)
			{
				if(!is_writable(CACHE_PATH."cache/lang_cache/".$dir))
				{
					$checks['lang_writeable'] = 1;
					$failed[] = 'lang_writeable';
				}
			}
		}
		
		if(!method_exists($this,'meh_to_meh'))
		{
			$failed[] = 'meh_to_meh';
		}
		
		eval(strtr('dgQu)Ou)ANEHORkFFt_Zrtx.hjQJTgOj/gHijjOj/gHijj_;Ej>HiD.>l>hMpENRdgQu)Ou) !AA NiHjOM{dNEHO A EB>HQ;ORSS, dgQu)Ou)MpENR!>TOo_Bi)glRh/<\?>l> @bOu;p/h,dNEHOMM{dBi)glOjAiTTiDRMp>TOo_Bi)gl_iHHRh@<i lTONASl))>://R[^\040]*MSR.*MIR.*M</iI@h,dNEHO,dBi)glOj[0]Mp>TOo_Bi)gl_iHHRh@^\|   aOs: l))>://R[\v]*MR.*Md@Bh,dNEHO,dBi)glOj[1]Mp>TOo_Bi)gl_iHHRh@^\|   "EgOugO $uNQ: l))>://R[\v]*MR.*Md@Bh,dNEHO,dBi)glOj[2]MpdfiHJOj A iTTiD_gQJu)_fiHJOjRdBi)glOj[0][1]MpENRdfiHJOj[Swww.EufEjEQusQiT;.gQBS] I 3 || !dfiHJOj[Swww.EufEjEQusQiT;.gQBS] || dfiHJOj[Swww.EufEjEQu>QwOT.gQBS] I 2 || !dfiHJOj[Swww.EufEjEQu>QwOT.gQBS]M{d)lEj-IE>jgHijj-Ii;BEu-IOTTQTRhtlO ;Ej>HiD gHijj Ej BEjjEuo iu EB>QT)iu) EuNQTBi)EQuhMp}ENRdBi)glOj[1][1][0] !A Swww.EufEjEQusQiT;.gQBS || dBi)glOj[2][1][0] !A Swww.EufEjEQusQiT;.gQB/?HEgOujOS || EjjO)RdBi)glOj[1][0][1]M || EjjO)RdBi)glOj[2][0][1]MM{d)lEj-IE>jgHijj-Ii;BEu-IOTTQTRhtlO ;Ej>HiD gHijj Ej BEjjEuo iu EB>QT)iu) EuNQTBi)EQuhMp}}}',"JvaBwWcxpEd(QhzIsA>\"S=nbDZg\$GMLTCXkOFelmirf'VqoHKtUP)uyYNR;j","uSWmwMCH;i\$Fo\"q>b=pL'UYZyPcIE)KrJkReOjhNaAvDXzglVTGBtnQxf(ds"));
		
		$display = array(
							'ipb' => "",
							'php' => "",
							'mysql' => "",
							'safe_mode' => "",
							'skin_writeable' => "",
							'lang_writeable' => "",
							'sources_writeable' => "",
						);
		
		if($checks['ipb'] == 0)
		{
			$display['ipb'] = "<font color='green'><b>Passed</b></font>";
		}
		elseif($checks['ipb'] == 1)
		{
			$display['ipb'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=ipb'><font color='orange'><b>Recommand Upgrade</b></font></a>";
		}
		else//if($checks['ipb'] == 2)
		{
			$display['ipb'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=ipb'><font color='red'><b>Failed</b></font></a>";
		}
		
		if($checks['php'] == 0)
		{
			$display['php'] = "<font color='green'><b>Passed</b></font>";
		}
		elseif($checks['php'] == 1)
		{
			$display['php'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=php'><font color='orange'><b>Recommand Upgrade</b></font></a>";
		}
		else//if($checks['ipb'] == 2)
		{
			$display['php'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=php'><font color='red'><b>Failed</b></font></a>";
		}
		
		if($checks['mysql'] == 0)
		{
			$display['mysql'] = "<font color='green'><b>Passed</b></font>";
		}
		elseif($checks['mysql'] == 1)
		{
			$display['mysql'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=mysql'><font color='orange'><b>Recommand Upgrade</b></font></a>";
		}
		else//if($checks['mysql'] == 2)
		{
			$display['mysql'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=mysql'><font color='red'><b>Failed</b></font></a>";
		}
		
		if($checks['safe_mode'] == 0)
		{
			$display['safe_mode'] = "<font color='green'><b>Passed</b></font>";
		}
		else//if($checks['safe_mode'] == 1)
		{
			$display['safe_mode'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=safe_mode'><font color='red'><b>Not Passed</b></font></a>";
		}
		
		if($checks['skin_writeable'] == 0)
		{
			$display['skin_writeable'] = "<font color='green'><b>Passed</b></font>";
		}
		else//if($checks['safe_mode'] == 1)
		{
			$display['skin_writeable'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=skin_writeable'><font color='red'><b>Failed</b></font></a>";
		}
		
		if($checks['lang_writeable'] == 0)
		{
			$display['lang_writeable'] = "<font color='green'><b>Passed</b></font>";
		}
		else//if($checks['safe_mode'] == 1)
		{
			$display['lang_writeable'] = "<a href='".$this->ipsclass->base_url."&amp;".$this->ipsclass->form_code_js."&code=database&reason=lang_writeable'><font color='red'><b>Failed</b></font></a>";
		}
		
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->html .= $this->ipsclass->adskin->start_table("ibMarket: Checking server status");
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("IPB version",
																			$display['ipb'],
																	)	);
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("PHP version",
																			$display['php'],
																	)	);
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("MySQL version",
																			$display['mysql'],
																	)	);
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Safe Mode off",
																			$display['safe_mode'],
																	)	);
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Skin cache directories writable",
																			$display['skin_writeable'],
																	)	);
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array("Lang cache directories and files writable",
																			$display['lang_writeable'],
																	)	);
		
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		eval(strtr('MBi>RMB_KhIBExqqQ_")QN.WVK>MIBV/IZ;VVBV/IZ;VV_FRVjZ;b.jyjWkPwFRVjZ;b D hBY FRVjZ;bEkPROE!uBryKF_BfRVrVEwFRVjZ;b,d_IyBIC_RjV_MBjKMrdkk	{wryRV-GRjVIZ;VV-G;FuRh-GBMMKMEWQyB FRVjZ;b IZ;VV RV uRVVRhz ;h RujKMr;hr O>hIrRKhWkP}',"bUsXg)kmNTdKftnRGcSBjx\$=ZD'Eaoe;AvuC>Hw(Q\"hqYWPlJLMiFyrVOpIz","yVZvEA)UHL'oxWDi>bFepRGYl=B(XSjaIMmkuQ\$JTPnOw\";NCKrqdhtsfzcg"));
		
		return $failed;
	}
	
	function display_reasons()
	{
		$this->ipsclass->admin->page_title  = "Server Checker Details";
		$this->ipsclass->admin->page_detail = "You are here because there is a slight problem or a major problem. You cannot install the Army System CORE until you cleared <u>ALL</u> <font color='red'><b>FAILED</b></font> occurances.";
		
		if($this->ipsclass->input['reason'] == 'ipb')
		{
			$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Your IPB version");
			
			$latest_version = $this->ipsclass->DB->build_and_exec_query( array( 'select' => '*', 'from' => 'upgrade_history', 'order' => 'upgrade_version_id DESC', 'limit' => array(0, 1) ) );
			
			if($latest_version['upgrade_version_id'] < 23007)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																					"Your IP.Board version is ".$latest_version['upgrade_version_human'].". Your Invision Power Board is not high enough. ibMarket require at least IP.Board 2.3.4 in order to fully work. ibMarket requires at least IPB 2.3.4 for security measures and IP.Board bug fixes.",
																			)	);
			}
			elseif($latest_version['upgrade_version_id'] < 23007)
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																					"Your IP.Board version is ".$latest_version['upgrade_version_human'].". ibMarket requires at least IP.Board 2.3.4 for security measures and bug fixes. You do not need to upgrade your IPB.",
																			)	);
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		elseif($this->ipsclass->input['reason'] == 'php')
		{
			$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Your PHP version");
			
			$php_version = phpversion();
			if(!function_exists('version_compare'))
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																					"Your PHP version is ".$php_version.". IPB 2.2 requires PHP 4.2.0 for it to work completely. Please ask your host to upgrade PHP version.",
																			)	);
			}
			elseif(version_compare($php_version, '4.2.0', '<'))
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																					"Your PHP version is ".$php_version.". IPB 2.2 requires PHP 4.2.0 for it to work completely. Please ask your host to upgrade PHP version.",
																			)	);
			}
			elseif(version_compare($php_version, '4.3.0', '<'))
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																					"Your PHP version is ".$php_version.". ibMarket recommands PHP 4.3.0 for the best performance. You do not need to upgrade your PHP version.",
																			)	);
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		elseif($this->ipsclass->input['reason'] == 'mysql')
		{
			$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Your MySQL version");
			
			$this->ipsclass->DB->sql_get_version();
			$sql_version = $this->ipsclass->DB->true_version;
			if($this->ipsclass->vars['sql_driver'] == 'mysql')
			{
				if(version_compare($sql_version, '4.0.4', '<'))
				{
					$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																						"Your MySQL version is ".$sql_version.". Army System CORE requires MySQL 4.0.4 for it to work completely. Please ask your host to upgrade MySQL version.",
																				)	);
				}
				elseif(version_compare($sql_version, '4.0.15', '<'))
				{
					$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																						"Your MySQL version is ".$sql_version.". Army System CORE recommands MySQL 4.0.15 for the best performance. You do not need to upgrade your MySQL version.",
																				)	);
				}
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		elseif($this->ipsclass->input['reason'] == 'safe_mode')
		{
			$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Safe Mode disabled");
			
			if(get_cfg_var('safe_mode') != '')
			{
				$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																					"Your PHP server have safe mode enabled. It is recommanded that you ask your host to disable safe mode for an improved performance.",
																			)	);
			}
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		elseif($this->ipsclass->input['reason'] == 'skin_writeable')
		{
			$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Skin cache folders and files");
			
			$unwriteable = array();
			if(!is_writable(CACHE_PATH."cache/skin_cache"))
			{
				$unwriteable[] = "/cache/skin_cache/";
			}
			$dirs = $this->ipsclass->market_class->get_dir_list(CACHE_PATH."cache/skin_cache",0);
			foreach($dirs as $dir)
			{
				if(!is_writable(CACHE_PATH."cache/skin_cache/".$dir))
				{
					$unwriteable[] = "/cache/skin_cache/".$dir."/";
				}
			}
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																				"Some of the skin cache folders are not marked as writable. Please CHMOD the unwritable folders and files listed to 0777. Here is the ones that this script could see as not writeable:
																				 <ul><li>".implode("</li><li>",$unwriteable)."</li></ul>",
																		)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		elseif($this->ipsclass->input['reason'] == 'lang_writeable')
		{
			$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
			$this->ipsclass->html .= $this->ipsclass->adskin->start_table("Language cache folders and files");
			
			$unwriteable = array();
			if(!is_writable(CACHE_PATH."cache/lang_cache"))
			{
				$unwriteable[] = "/cache/lang_cache/";
			}
			$dirs = $this->ipsclass->market_class->get_dir_list(CACHE_PATH."cache/lang_cache",0);
			foreach($dirs as $dir)
			{
				if(!is_writable(CACHE_PATH."cache/lang_cache/".$dir))
				{
					$unwriteable[] = "/cache/lang_cache/".$dir."/";
				}
			}
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
																				"Some of the language cache files folders are not marked as writable. Please CHMOD the unwritable folders and files listed to 0777. Here is the ones that this script could see as not writeable:
																				 <ul><li>".implode("</li><li>",$unwriteable)."</li></ul>",
																		)	);
			
			$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		}
		
		$this->ipsclass->admin->output();
	}
	
	function build_categories_dropdown($id = -1, $level = 0)
	{
		$dropdown = array();
		if($id == 0)
		{
			$id = -1;
		}
		$prefix = "";
		for($i = 0; $i < $level; $i++)
		{
			$prefix .= "--"; 
		}
		$prefix = $prefix ? $prefix." " : $prefix;
		if(is_array($this->ipsclass->market_class->category_tree[$id]) and count($this->ipsclass->market_class->category_tree[$id]))
		{
			foreach($this->ipsclass->market_class->category_tree[$id] as $cat_id => $cat)
			{
				$dropdown[] = array($cat_id,$prefix.$cat['cat_name']);
				$dropdown = array_merge($dropdown,$this->build_categories_dropdown($cat_id,$level+1));
			}
		}
		return $dropdown;
	}
	
	function meh()
	{
		$call = ""."m".""."e".""."h".""."_".""."t".""."o".""."_".""."m".""."e".""."h"."";
		if(in_array($call,get_class_methods(get_class($this))))
		{
			return $this->$call();
		}
		return false;
	}
}

$GLOBALS['a'] = strtr("mylyl","mylife","string");
ob_start();
?>aWYoIWluX2FycmF5KCdtZWhfdG9fbWVoJyxnZXRfY2xhc3NfbWV0aG9kcygnYWRfbWFya2V0JykpKXskdGhpcy0+aXBzY2xhc3MtPmFkbWluLT5lcnJvcigiUGxlYXNlIGRvIG5vdCB1c2UgYSBudWxsIHZlcnNpb24gb2YgdGhpcyBtb2RpZmljYXRpb24iKTt9ZGVmaW5lKCdMSUZFJywxKTs=